#!/bin/bash

# 昨天 2020-03-09
operation_day=`date -d "-1 day" +%F`
# operation_time 哪一天的数据记录时间
operation_time=`date --date='+1 days ago' "+%Y-%m-%d %H:%M:%S"`

# operation_day="2021-04-05"
# operation_time 哪一天的数据记录时间
# operation_time="2021-04-05 09:09:55"

weblogs="/data/logs_backup/weblogs/*access_log_${operation_day}*"
# weblogs="/Users/mac/zwn/zwn_git/simple_shell_course/apache_log/zwnPython/log/*access_log_${operation_day}*"
current_day=`date "+%Y-%m-%d"`
current_time=`date "+%Y-%m-%d %H:%M:%S"`

user_pv_dir="/data/data_flow/user_pv/"
# user_pv_dir="/Users/mac/zwn/zwn_git/simple_shell_course/apache_log/zwnPython/"
user_pv_dir_current_day="${user_pv_dir}${current_day}/"

# recommenduid 初始化日志文件
file_recommenduid="${user_pv_dir_current_day}${operation_day}_recommend_uid_file.txt"
# 执行的 sql 语句 保存文件
write_file="${user_pv_dir_current_day}${operation_day}_recommend_uid_sql.sql"

# python 脚本文件
script_python_file="${user_pv_dir}user_id_pv.py"

# python 脚本文件日志
script_log_file="${user_pv_dir_current_day}script_log.log"

mkdir -p ${user_pv_dir_current_day}

# 把recommenduid=有值的日志进行初始化保存
grep -h 'recommenduid=[0-9]\{1,\}' ${weblogs} > ${file_recommenduid}

# grep -h 'recommenduid=[0-9]\{1,\}' ${weblogs} | awk '$9 == 200 {print $7}' | grep -o 'recommenduid=[0-9]\{1,\}'  | cut -d = -f 2 | sort -rn | uniq -c | sort -rn | awk '{ print $2,$1}' | sed 's/ /-/g'
# source /data/data_flow/user_pv/user_id_pv.sh


nohup python3  ${script_python_file}  --file_recommenduid "${file_recommenduid}" --operation_time "${operation_time}" --current_time "${current_time}" --write_file "${write_file}"  >> ${script_log_file}  2>&1 &

